uniform vec3 diffuse;

uniform sampler2D tDepth;
uniform float opacity;
varying float depth;
varying vec2 depthUv;

float decodeRGBA2Float(vec4 rgba)
{
    return dot(rgba,vec4(1.,1./255.,1./65025.,1./16581375.));
}

#ifndef FLAT_SHADED
varying vec3 vNormal;
#endif
#include <common>
#include <dithering_pars_fragment>
#include <color_pars_fragment>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <alphamap_pars_fragment>
#include <alphatest_pars_fragment>
#include <alphahash_pars_fragment>
#include <aomap_pars_fragment>
#include <lightmap_pars_fragment>
#include <envmap_common_pars_fragment>
#include <envmap_pars_fragment>
#include <fog_pars_fragment>
#include <specularmap_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>
void main(){
    
    if(1.-depth<decodeRGBA2Float(texture2D(tDepth,depthUv)))discard;
    vec4 diffuseColor=vec4(diffuse,opacity);
    
    #include <clipping_planes_fragment>
    #include <logdepthbuf_fragment>
    #include <map_fragment>
    #include <color_fragment>
    #include <alphamap_fragment>
    #include <alphatest_fragment>
    #include <alphahash_fragment>
    #include <specularmap_fragment>
    ReflectedLight reflectedLight=ReflectedLight(vec3(0.),vec3(0.),vec3(0.),vec3(0.));
    #ifdef USE_LIGHTMAP
    vec4 lightMapTexel=texture2D(lightMap,vLightMapUv);
    reflectedLight.indirectDiffuse+=lightMapTexel.rgb*lightMapIntensity*RECIPROCAL_PI;
    #else
    reflectedLight.indirectDiffuse+=vec3(1.);
    #endif
    #include <aomap_fragment>
    reflectedLight.indirectDiffuse*=diffuseColor.rgb;
    vec3 outgoingLight=reflectedLight.indirectDiffuse;
    #include <envmap_fragment>
    #include <opaque_fragment>
    #include <tonemapping_fragment>
    #include <colorspace_fragment>
    #include <fog_fragment>
    #include <premultiplied_alpha_fragment>
    #include <dithering_fragment>
}